package cx.com.diy.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.example.xiaocongtv.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AbsListView.OnScrollListener;

public class ImageAdapter extends BaseAdapter implements OnScrollListener, OnClickListener  {
	/**
	 * Image Url锟斤拷锟斤拷锟斤拷
	 */
	private ArrayList<HashMap<String, Object>>  list;
	
	private  LayoutInflater inflater=null;
	/**
	 * Image 锟斤拷锟斤拷锟斤拷
	 */
	//private ImaeLoad imageLoader;
	

	/**
	 * 一锟斤拷锟叫碉拷一锟斤拷item锟斤拷位锟斤拷
	 */
private boolean mBusy = false;
	private Context context;
	public void setFlagBusy(boolean busy) {
		this.mBusy = busy;
	}
	protected  final String TAG = "ImageAdapter";
	
	public ImageAdapter(Context context, ListView mGridView, ArrayList<HashMap<String, Object>>  arrayList){
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.list = arrayList;
		this.context=context;
		//this.imageLoader=new ImaeLoad(context); 
	}
	
	

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public HashMap<String, Object>getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	 public class ViewHolder{
	    
			TextView title;
			TextView type;
			TextView size;
			TextView content;
			TextView url;
			ImageView imageView;
	    	
	    }
	 @Override  
	 public boolean isEnabled(int position) {   
	    return false;   
	 }
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Log.d(TAG, "getView=" + position + ",convertView=" + convertView);
		ViewHolder viewHolder = null;
		View vi = convertView; 
		if (convertView == null) {
			vi = inflater.inflate(R.layout.scenic_item_list, null);
			viewHolder = new ViewHolder();
			viewHolder.imageView = (ImageView) vi.findViewById(R.id.item_img);
			viewHolder.title = (TextView) vi.findViewById(R.id.item_title);
			viewHolder.type = (TextView) vi.findViewById(R.id.item_type);
			viewHolder.size = (TextView) vi.findViewById(R.id.item_size);
			viewHolder.content = (TextView) vi
					.findViewById(R.id.item_instruction);
			viewHolder.url = (TextView) vi.findViewById(R.id.item_install);
			vi.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		HashMap<String, Object> application = new HashMap<String, Object>();
		application = list.get(position);

		viewHolder.imageView.setBackgroundResource((Integer) application
				.get("image"));
		viewHolder.title.setText((String) application.get("title"));
		viewHolder.type.setText((String) application.get("type"));
		viewHolder.size.setText((String) application.get("size"));
		viewHolder.content.setText((String) application.get("instruction"));
		viewHolder.url.setText((String) application.get("url"));
		viewHolder.url.setOnClickListener(this);
	
	 /*if(!mBusy){
		imageLoader.DisplayImage("http://10.202.1.45:8080/EverLush/upload/"+song.get("Images"), wrapper.chef_image);
			    }else{
			    	wrapper.chef_image.setBackgroundResource(R.drawable.ti);
			    }*/
	
   
 return vi;
	}
	
	/**
	 * 锟斤拷示锟斤拷前锟斤拷幕锟斤拷图片锟斤拷锟饺伙拷去锟斤拷锟斤拷LruCache锟斤拷LruCache没锟叫撅拷去sd锟斤拷锟斤拷锟斤拷锟街伙拷目录锟斤拷锟揭ｏ拷锟斤拷没锟叫就匡拷锟斤拷锟竭筹拷去锟斤拷锟斤拷
	 * @param firstVisibleItem
	 * @param visibleItemCount
	 */
	
	

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		switch (scrollState) {
		case OnScrollListener.SCROLL_STATE_FLING:
			this.setFlagBusy(true);
			break;
		case OnScrollListener.SCROLL_STATE_IDLE:
			this.setFlagBusy(false);
			break;
		case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
			this.setFlagBusy(false);
			break;
		default:
			break;
		}
		this.notifyDataSetChanged();
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {

	}



	/**
	 * 重载方法
	 * @param arg0
	 */
	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		Toast.makeText(context, "XX", Toast.LENGTH_LONG).show();
	}

	
}
